package demo;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import demo.work.MySequentialWork;
import taskflow.constants.Parameter;
import taskflow.work.AbstractWork;
import taskflow.work.Work;
import taskflow.work.WorkFactory;

/**
 * Sequential Work
 * 
 * @author bailey
 * @date 2021年8月19日
 */
public class SequentialDemoApplication {
	
	public static void main(String[] args) throws Exception{
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:serial-task-config.xml");
		//后执行的优先级高；此时默认的maxTasks为66而不是application.properties中定义的值
		System.out.println("Default max tasks=" + Parameter.WORK_MAX_TASKS.getValue());
		Parameter.WORK_MAX_TASKS.setValue("66");
		try {
			Work testWork = WorkFactory.createWork("mySequentialTaskWork");
			System.out.println("before MaxTasks="+((AbstractWork) testWork).getMaxTasks());
			//设置当前maxTasks值为88，优先级最高
			((AbstractWork)testWork).setMaxTasks(88);
			testWork.run();
			System.out.println("after MaxTasks="+((AbstractWork) testWork).getMaxTasks());
			System.out.println("Work's tagName is "+((MySequentialWork)testWork).getTagName());
		}catch(Exception e) {
			throw e;
		}finally {
			context.close();
		}
	}
}
